home *** CD-ROM | disk | FTP | other *** search
- Path: rcp6.elan.af.mil!rscernix!danpop
- From: danpop@mail.cern.ch (Dan Pop)
- Newsgroups: comp.lang.c
- Subject: Re: What to do when feof() is NOT feof()
- Date: 20 Feb 96 01:26:03 GMT
- Organization: CERN European Lab for Particle Physics
- Message-ID: <danpop.824779563@rscernix>
- References: <824554814snz@metsys.demon.co.uk> <4g4vpp$52f@spectator.cris.com> <danpop.824614833@rscernix> <4g7t1r$71s@crl13.crl.com> <4gath3$abv@epx.cis.umn.edu>
- NNTP-Posting-Host: ues5.cern.ch
- X-Newsreader: NN version 6.5.0 #7 (NOV)
-
- In <4gath3$abv@epx.cis.umn.edu> thornley@cs.umn.edu (David H. Thornley) writes:
-
- >tried to read past the end of file. (Now, if feof() would tell me
- >that I'm *going* to read past EOF, I'd find it a bit more useful.)
-
- Unfortunately, predicting the future is not an easy task :-)
- Let's consider a few examples:
-
- - The stream is connected to a serial device in text mode. No way to tell
- whether the next character will be the end of file marker (if such a
- beast is used) or if the tty driver will report EOF in five minutes,
- because the user (who has just fallen asleep) will press the EOF
- key combination. A feof() which can block indefinitely is not
- particularly desirable.
-
- - The stream is connected to a file which is continuously growing, because
- another program is madly writing into it.
-
- - The stream is connected to a pipe. It's difficult to tell what's
- happening at the other end of the pipe.
-
- The purpose of feof() is not to detect the end of file condition, but to
- report it. It is typically used when another stdio function has returned
- an "error" condition and the programmer wants to know whether it was
- simply an attempt to read more data than was available on the stream and
- the data supply of that stream is definitively exhausted or something
- else happened on that stream.
-
- To end the discussion on this topic, here's what the standard says about
- feof:
-
- 4.9.10.2 The feof function
-
- Synopsis
-
- #include <stdio.h>
- int feof(FILE *stream);
-
- Description
-
- The feof function tests the end-of-file indicator for the stream
- pointed to by stream.
-
- Returns
-
- The feof function returns nonzero if and only if the end-of-file
- indicator is set for stream.
-
- Dan
- --
- Dan Pop
- CERN, CN Division
- Email: danpop@mail.cern.ch
- Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
-